from forms.uipy.UI_MEleFileSelected import Ui_MEleFileSelected
from PySide2.QtWidgets import QWidget
from tools.File_Select_Tools import File_Select_Tools
from server.EleAccountServer import ElecAccountServer

class MEleFileSelected(QWidget, Ui_MEleFileSelected):
    """
    工具菜单 ==> 电子记账汇总UI实现类
    """
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.__initBindEvent()

    def __initBindEvent(self):
        """
        初始化绑定事件方法
        :return: None
        """
        # 绑定前月记账概览文件选择
        self.preOverviewPathBtn.clicked.connect(lambda : self.__file_selected(1))
        # 绑定当月记账概览文件选择
        self.nowOverviewPathBtn.clicked.connect(lambda: self.__file_selected(2))
        # 绑定前月记账概览文件选择
        self.nowReviewPathBtn.clicked.connect(lambda: self.__file_selected(3))
        # 绑定运行按钮
        self.okbtn.clicked.connect(lambda: ElecAccountServer(self.preOverviewPath.text(),
                                                             self.nowOverviewPath.text(),
                                                             self.nowReviewPath.text()).initData())

    def __file_selected(self,flag=1):
        if flag == 1:
            self.preOverviewPath.setText(File_Select_Tools.select_one_file(title="前月记账概览文件选择")[0])
        elif flag == 2:
            self.nowOverviewPath.setText((File_Select_Tools.select_one_file(title="当月记账概览文件选择")[0]))
        else:
            self.nowReviewPath.setText((File_Select_Tools.select_one_file(title="当月记账复核文件选择")[0]))

